package com.xuelang.pipeline.worker.client.crd;

import com.xuelang.pipeline.worker.client.common.feign.TektonServiceFallbackImpl;
import com.xuelang.pipeline.worker.client.common.result.ApiResult;
import com.xuelang.pipeline.worker.client.crd.dto.PipelineDTO;
import com.xuelang.pipeline.worker.client.crd.dto.PipelineRunDTO;
import com.xuelang.pipeline.worker.client.crd.tekton.v1beta.pipeline.V1Beta1Pipeline;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import jakarta.validation.Valid;
import java.util.List;

/**
 * @author liuyuan.ly
 * @since 2024/5/29 9:48
 */
@FeignClient(name = "tekton-service", url = "${feign.rpc.workerService}",
        fallback = TektonServiceFallbackImpl.class)
public interface IPipelineService {

    /**
     * 创建pipeline资源
     *
     * @param dto
     * @return
     */
    @PostMapping(value = "/create/crd/pipeline", produces = "application/json;charset=utf-8")
    ApiResult<Boolean> createPipeline(@RequestBody @Valid PipelineDTO dto);

    /**
     * 查询pipeline资源列表
     *
     * @param dto
     * @return
     */
    @PostMapping(value = "/get/crd/pipeline/list", produces = "application/json;charset=utf-8")
    ApiResult<List<V1Beta1Pipeline>> getPipelineList(@RequestBody @Valid PipelineDTO dto);

    /**
     * 创建pipelinerun资源
     *
     * @param dto
     * @return
     */
    @PostMapping(value = "/create/crd/pipelineRun", produces = "application/json;charset=utf-8")
    ApiResult<Boolean> createPipelineRun(@RequestBody @Valid PipelineRunDTO dto);

    /**
     * 查询pipelinerun资源列表
     *
     * @param dto
     * @return
     */
    @PostMapping(value = "/get/crd/pipelineRun/list", produces = "application/json;charset=utf-8")
    ApiResult<String> getPipelineRunList(@RequestBody @Valid PipelineRunDTO dto);


    /**
     * 停止/取消 运行流水线
     * @param pipelineRunDTO
     * @return
     */
    @PostMapping(value = "/cancel/crd/pipelineRun", produces = "application/json;charset=utf-8")
    ApiResult<Boolean> cancelPipelineRun(@RequestBody @Valid PipelineRunDTO pipelineRunDTO);
}

